const jwt = require('jsonwebtoken')

// 生成token
function generateToken(user, expiresIn) {
  const payload = {
    id: user.id,
    username: user.username,
    email: user.email
  }
  const secretKey = 'your_secret_key'
  const options = {
    expiresIn: expiresIn
  }
  return jwt.sign(payload, secretKey, options)
}

// 验证token
function verifyToken(token) {
  const secretKey = 'your_secret_key'
  const decoded = jwt.verify(token, secretKey)
  return decoded
}

module.exports = {
  generateToken,
  verifyToken
}